<template>
  <a-modal
    :title="$t('会员详情')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
    class="customHeight customHeightChild modal_title"
    v-drag
  >
    <template slot="footer">
      <a-button @click="handleCancel">{{ $t('关闭') }}</a-button>
    </template>
    <a-spin style="min-height: 678px" :spinning="confirmLoading" ref="modalcontent" class="tableSpinPadding">
      <a-tabs v-model="activeKey" @change="callback" :tabBarStyle="tabBarStyle">
        <a-tab-pane key="1" :tab="$t('基本信息')">
          <a-form>
            <a-row :gutter="24">
              <a-col :span="8">
                <div style="font-weight: bold; font-size: 15px; margin: 10px">{{ $t('身份信息') }}</div>
                <a-form-item
                  class="noborder"
                  :label="$t('会员ID')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="model.id" />
                </a-form-item>
                <a-form-item
                  class="noborder"
                  :label="$t('手机号')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input ref="phone" v-model="model.phone" oninput="value=value.replace(/\D/g,'');" />
                </a-form-item>
                <a-form-item
                  class="noborder"
                  :label="$t('邮箱')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input v-model="model.email" />
                </a-form-item>
                <a-form-item
                  :label="$t('会员姓名')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input v-model="model.name" />
                </a-form-item>
                <a-form-item
                  :label="$t('性别')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <j-dict-select-tag v-model="model.sex" dictCode="bis_member.sex"></j-dict-select-tag>
                </a-form-item>
                <a-form-item
                  :label="$t('证件类型')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <j-dict-select-tag v-model="model.certType" dictCode="bis_member.cert_type"></j-dict-select-tag>
                </a-form-item>
                <a-form-item
                  :label="$t('证件号码')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input v-model="model.certno" />
                </a-form-item>
                <a-form-item
                  :label="$t('会员生日')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-date-picker
                    :show-time="true"
                    format="YYYY-MM-DD"
                    class="query-group-cust"
                    valueFormat="YYYY-MM-DD HH:mm:ss"
                    v-model="model.birthday"
                    style="width: 100%"
                  ></a-date-picker>
                </a-form-item>
                <a-form-item
                  :label="$t('居住国家')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="profile.country" />
                </a-form-item>
                <a-form-item
                  :label="$t('居住地址')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="profile.address" />
                </a-form-item>
                <!-- <a-form-item
                  :label="$t('微信昵称')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="model.wxNickName" />
                </a-form-item>
                <a-form-item label="OpenID" :labelCol="labelCol" :wrapperCol="wrapperCol" style="margin-bottom: 14px">
                  <a-input disabled v-model="model.wxOpenid" />
                </a-form-item>
                <a-form-item
                  :label="$t('微信头像')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-upload listType="picture-card" class="avatar-uploader" :showUploadList="false" :data="{ isup: 1 }">
                    <img
                      v-if="picUrl"
                      :src="model.wxHeadImg"
                      :alt="$t('头像')"
                      style="height: 104px; max-width: 300px"
                    />
                  </a-upload>
                </a-form-item> -->
                <a-button type="primary" v-has="'MemberInfoList:edit'" @click="handleOk">{{ $t('保存') }}</a-button>
                <a-popconfirm
                  v-if="model.unbind && model.memberCards.length > 0"
                  style="margin-left: 10px"
                  :title="$t('您确定要进行解绑吗？')"
                  @confirm="() => unbundle()"
                >
                  <a-button>{{ $t('解绑') }}</a-button>
                </a-popconfirm>
              </a-col>
              <a-col :span="8">
                <div style="font-weight: bold; font-size: 15px; margin: 10px">{{ $t('账户信息') }}</div>
                <a-form-item
                  :label="$t('代币')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.coin"

                                  :formatter="formatter"
                                  :parser="parser"

                                  style="width: 100%;" />
                </a-form-item>
                <a-form-item
                  :label="$t('真实代币')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.realCoin"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                                  :precision="2"
                  />
                </a-form-item>
                <a-form-item
                  :label="$t('赠送代币')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.presentCoin"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"

                  />
                </a-form-item>
                <a-form-item
                  :label="$t('积分')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.integral"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  />
                </a-form-item>
                <a-form-item
                  :label="$t('彩票')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.lottery"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  />
                </a-form-item>
                <a-form-item
                  :label="$t('A票')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.alottery"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  />
                </a-form-item>
                <a-form-item
                  :label="$t('A币')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.points" />
                </a-form-item>
                <a-form-item
                  :label="$t('成长值')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input-number disabled v-model="memberAccount.growth"

                                  :formatter="formatter"
                                  :parser="parser"
                                  style="width: 100%;"
                  />
                </a-form-item>
                <a-form-item
                  :label="$t('有效期至')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.validityEnd" />
                </a-form-item>
              </a-col>
              <a-col :span="8">
                <div style="font-weight: bold; font-size: 15px; margin: 10px">{{ $t('其它信息') }}</div>
                <a-form-item
                  :label="$t('会员类型')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.memberType" />
                </a-form-item>
                <a-form-item
                  :label="$t('账户状态')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input
                    v-if="memberAccount.state == 0"
                    disabled
                    v-model="memberAccount.state_dictText"
                    style="color: green"
                  />
                  <a-input v-else disabled v-model="memberAccount.state_dictText" style="color: red" />
                </a-form-item>
                <a-form-item
                  :label="$t('账户来源')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.source_dictText" />
                </a-form-item>
                <a-form-item
                  :label="$t('注册渠道')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.channel_dictText" />
                </a-form-item>
                <a-form-item
                  :label="$t('注册时间')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="memberAccount.regTime" />
                </a-form-item>
                <a-form-item
                  :label="$t('备注')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="model.commet" />
                </a-form-item>
                <a-form-item
                  :label="$t('获知渠道')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="profile.channelName" />
                </a-form-item>
                <a-form-item
                  :label="$t('个人喜好')"
                  :labelCol="labelCol"
                  :wrapperCol="wrapperCol"
                  style="margin-bottom: 14px"
                >
                  <a-input disabled v-model="profile.hobbyName" />
                </a-form-item>
                <a-form-item style="margin-bottom: 14px" v-if="appletAuthRecharge">
                  <a-checkbox style="margin-left: 38px" v-model="model.allowAppletRecharge" @change="handleOk">{{
                    $t('允许小程序充值')
                  }}</a-checkbox>
                </a-form-item>
              </a-col>
            </a-row>
          </a-form>
        </a-tab-pane>
        <a-tab-pane key="2" :tab="$t('门票')" :confirmLoading="confirmLoading">
          <div style="margin: 0 10px">
            <a-form>
              <a-row>
                <a-col :span="5">
                  <a-form-item
                    :label="$t('状态')"
                    :labelCol="{ span: 4 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 14px"
                  >
                    <j-dict-select-tag
                      v-model="piaoModel.state"
                      :placeholder="$t('请选择')"
                      dictCode="bis_member_ticket.state"
                    ></j-dict-select-tag>
                  </a-form-item>
                </a-col>
                <a-col :span="7">
                  <a-form-item
                    :label="$t('次票名称')"
                    :labelCol="{ span: 6 }"
                    :wrapperCol="{ span: 16 }"
                    style="margin-bottom: 14px"
                  >
                    <a-input :placeholder="$t('请输入次票名称')" v-model="piaoModel.goodsName" />
                  </a-form-item>
                </a-col>

                <a-col :span="3">
                  <a-button type="primary" @click="getPiao(1)" icon="search">{{ $t('查询') }}</a-button>
                </a-col>
              </a-row>
            </a-form>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="piaoColumns"
              :dataSource="piaoDataSource"
              class="j-table-force-nowrap"
              :loading="loadings"
              :pagination="ipagination"
              @change="handlePiaoTableChange"
            >
              <span slot="state" slot-scope="text, record">
                <div v-if="record.state == '0'" style="color: green">{{ record.state_dictText }}</div>
                <div v-else style="color: red">{{ record.state_dictText }}</div>
              </span>
              <span slot="action" slot-scope="text, record">
                <a-popconfirm
                  v-if="record.state != '4'"
                  :title="$t('void-ticket',{id:record.id,goodsName:record.goodsName})"
                  @confirm="() => handleInvalid(record)"
                >
                  <a>{{ $t('作废') }}</a>
                </a-popconfirm>
                <a @click="viewTicketDetail(record)" style="margin-left: 8px">{{ $t('消费明细') }}</a>
              </span>
            </a-table>
          </div>
        </a-tab-pane>
        <a-tab-pane key="3" :tab="$t('优惠券')">
          <div style="margin: 0 10px">
            <a-form>
              <a-row>
                <a-col :span="5">
                  <a-form-item :label="$t('状态')" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
                    <j-dict-select-tag v-model="coupon.state" dictCode="bis_member_coupon.state"></j-dict-select-tag>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-form-item :label="$t('来源')" :labelCol="{ span: 6 }" :wrapperCol="{ span: 17 }">
                    <j-dict-select-tag
                      v-model="coupon.getType"
                      :placeholder="$t('请选择')"
                      dictCode="bis_member_coupon.get_type"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="7">
                  <a-form-item
                    :label="$t('优惠券')"
                    :labelCol="{ span: 4 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 14px"
                  >
                    <a-input :placeholder="$t('请输入优惠券名称')"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-button type="primary" style="margin-left: 8px" @click="couponSearchQuery(1)" icon="search">{{
                    $t('查询')
                  }}</a-button>
                </a-col>
              </a-row>
            </a-form>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="couponColumns"
              :dataSource="couponDataSource"
              class="j-table-force-nowrap"
              :loading="loadings"
              :pagination="ipagination"
              @change="handleCouponTableChange"
            >
              <span slot="state" slot-scope="text, record">
                <div style="color: green" v-if="record.state == 0">{{ record.state_dictText }}</div>
                <div style="color: red" v-else>{{ record.state_dictText }}</div>
              </span>
              <span slot="action" slot-scope="text, record">
                <a-popconfirm
                  v-if="record.state != '4'"
                  :title="$t('void-coupon',{couponId:record.couponId,name:record.name})"
                  @confirm="() => couponDel(record)"
                >
                  <a>{{ $t('作废') }}</a>
                </a-popconfirm>
              </span>
            </a-table>
          </div>
        </a-tab-pane>
        <a-tab-pane key="6" :tab="$t('限时币')">
          <div style="margin: 0 10px">
            <a-form>
              <a-row>
                <a-col :span="5">
                  <a-form-item :label="$t('状态')" :labelCol="{ span: 4 }" :wrapperCol="{ span: 20 }">
                    <j-dict-select-tag
                      v-model="limitCoin.state"
                      dictCode="bis_member_limit_coin.state"
                    ></j-dict-select-tag>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-form-item :label="$t('来源')" :labelCol="{ span: 6 }" :wrapperCol="{ span: 17 }">
                    <j-dict-select-tag
                      v-model="limitCoin.source"
                      :placeholder="$t('请选择')"
                      dictCode="bis_member_limit_coin.source"
                    />
                  </a-form-item>
                </a-col>
                <a-col :span="7">
                  <a-form-item
                    :label="$t('限时币')"
                    :labelCol="{ span: 4 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 14px"
                  >
                    <a-input :placeholder="$t('请输入限时币名称')"></a-input>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-button type="primary" style="margin-left: 8px" @click="limitCoinSearchQuery(1)" icon="search">{{
                    $t('查询')
                  }}</a-button>
                </a-col>
              </a-row>
            </a-form>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="limitCoinColumns"
              :dataSource="limitCoinDataSource"
              class="j-table-force-nowrap"
              :loading="loadings"
              :pagination="ipagination"
              @change="handleLimitCoinTableChange"
            >
              <span slot="state" slot-scope="text, record">
                <div style="color: green" v-if="record.state == 0">{{ record.state_dictText }}</div>
                <div style="color: red" v-else>{{ record.state_dictText }}</div>
              </span>
              <span slot="action" slot-scope="text, record">
                <a-popconfirm
                  v-if="record.state != '4'"
                  :title="$t('void-limitcoin',{id:record.id,goodsName:record.goodsName})"
                  @confirm="() => limitCoinDel(record)"
                >
                  <a>{{ $t('作废') }}</a>
                </a-popconfirm>
              </span>
            </a-table>
          </div>
        </a-tab-pane>
        <a-tab-pane key="4" :tab="$t('会员卡')">
          <div style="margin: 0 10px">
            <a-form>
              <a-row>
                <a-col :span="5">
                  <a-form-item
                    :label="$t('卡号')"
                    :labelCol="{ span: 4 }"
                    :wrapperCol="{ span: 20 }"
                    style="margin-bottom: 14px"
                  >
                    <a-input :placeholder="$t('请输入卡号')" v-model="cardModel.chipNo" />
                  </a-form-item>
                </a-col>
                <a-col :span="7">
                  <a-form-item
                    :label="$t('状态')"
                    :labelCol="{ span: 4 }"
                    :wrapperCol="{ span: 18 }"
                    style="margin-bottom: 14px"
                  >
                    <j-dict-select-tag
                      v-model="cardModel.state"
                      :placeholder="$t('请选择')"
                      dictCode="bis_member_card.state"
                    ></j-dict-select-tag>
                  </a-form-item>
                </a-col>
                <a-col :span="3">
                  <a-button type="primary" @click="cardSearchQuery" icon="search">{{ $t('查询') }}</a-button>
                </a-col>
              </a-row>
            </a-form>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              :columns="cardColumns"
              :dataSource="cardDataSource"
              class="j-table-force-nowrap"
              :loading="loadings"
              :pagination="false"
            >
              <span slot="action" slot-scope="text, record">
                <a @click="editmemberLimit(record)">{{ $t("编辑") }}</a>
              </span>
            </a-table>
          </div>
        </a-tab-pane>
        <a-tab-pane key="5" :tab="$t('消费记录')">
          <div style="margin: 0 10px">
            <a-form>
              <a-row>
                <a-col :span="11">
                  <a-form-item :label="$t('业务时间')" :labelCol="{ span: 3 }" :wrapperCol="{ span: 20 }">
                    <a-date-picker
                      :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                      valueFormat="YYYY-MM-DD HH:mm:ss"
                      dateFormat="YYYY-MM-DD HH:mm:ss"
                      :placeholder="$t('请选择开始时间')"
                      class="query-group-cust"
                      v-model="recordsModel.createTime_begin"
                    ></a-date-picker
                    >~
                    <a-date-picker
                      :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                      valueFormat="YYYY-MM-DD HH:mm:ss"
                      dateFormat="YYYY-MM-DD HH:mm:ss"
                      :placeholder="$t('请选择结束时间')"
                      class="query-group-cust"
                      v-model="recordsModel.createTime_end"
                    ></a-date-picker>
                  </a-form-item>
                </a-col>
                <a-col :span="6">
                  <a-form-item
                    :label="$t('业务类型')"
                    :labelCol="{ span: 6 }"
                    :wrapperCol="{ span: 17 }"
                    style="margin-bottom: 14px"
                  >
                    <j-dict-select-tag
                      v-model="recordsModel.typeId"
                      :placeholder="$t('请选择')"
                      dictCode="bis_order.type"
                    ></j-dict-select-tag>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-button type="primary" @click="getRecordsList(1)" icon="search">{{ $t('查询') }}</a-button>
                </a-col>
              </a-row>
              <a-row>
                <a-col :span="5">
                  <a-form-item :label="$t('操作员')" :labelCol="{ span: 6 }" :wrapperCol="{ span: 18 }">
                    <a-select v-model="recordsModel.createBy">
                      <a-select-option v-for="(item, index) in userList" :value="item.id" :key="index">{{
                        item.realname
                      }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
                <a-col :span="5">
                  <a-form-item :label="$t('设备')" :labelCol="{ span: 6 }" :wrapperCol="{ span: 17 }">
                    <a-select v-model="recordsModel.deviceId">
                      <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">{{
                        item.name
                      }}</a-select-option>
                    </a-select>
                  </a-form-item>
                </a-col>
              </a-row>
            </a-form>
            <a-table
              ref="table"
              size="middle"
              bordered
              rowKey="id"
              class="j-table-force-nowrap"
              :scroll="{ x: true }"
              :columns="recordsColumns"
              :dataSource="recordsDataSource"
              :loading="loading"
              :pagination="ipagination"
              @change="handleTableChange"
            >
              <span s slot="createTime" slot-scope="text, record">
                <a v-if="record.orderId" @click="showOrder(record)">{{ text }}</a>
                <span v-else>{{ text }}</span>
              </span>
            </a-table>
          </div>
        </a-tab-pane>
      </a-tabs>
    </a-spin>
    <ticket-details-modal ref="ticketDetails"></ticket-details-modal>
    <type-name-modal ref="typeNameForm"></type-name-modal>
    <member-limit-modal ref="limit" @ok="cardSearchQuery"></member-limit-modal>
  </a-modal>
</template>

<script>
import moment from 'moment'
import { getAction, postAction, putAction } from '@/api/manage'
import TicketDetailsModal from './TicketDetailsModal'
import TypeNameModal from '../../order/modules/TypeNameModal'
import MemberLimitModal from './MemberLimitModal'
import {formatter, parser} from "@api/comm";

export default {
  name: 'MemberInfoModal',
  components: { TicketDetailsModal, TypeNameModal, MemberLimitModal },
  data() {
    return {
      formatter,
      parser,
      moment,
      tabBarStyle: {
        'font-weight': 'bold',
      },
      title: '',
      width: 1200,
      visible: false,
      disableSubmit: false,
      confirmLoading: false,
      activeKey: '1',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 7 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 15 },
      },
      //基本信息
      model: {},
      memberAccount: {},
      profile: {},
      picUrl: false,
      appletAuthRecharge: false,
      //门票
      piaoDataSource: [],
      piaoModel: {
        state: '0',
      },
      piaoColumns: [
        {
          title: this.$t('票号'),
          align: 'center',
          dataIndex: 'ticketNo',
        },
        {
          title: this.$t('名称'),
          align: 'center',
          dataIndex: 'goodsName',
        },
        {
          title: this.$t('总次数'),
          align: 'right',
          dataIndex: 'totalNumber',
        },
        {
          title: this.$t('剩余次数'),
          align: 'right',
          dataIndex: 'remainNumber',
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state_dictText',
          scopedSlots: { customRender: 'state' },
        },
        {
          title: this.$t('有效期'),
          align: 'center',
          dataIndex: 'validity',
        },
        {
          title: this.$t('获取时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('最后消费时间'),
          align: 'center',
          dataIndex: 'updateTime',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      //优惠券
      coupon: {
        state: '0',
        getType: undefined,
      },
      couponColumns: [
        {
          title: this.$t('券号'),
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: this.$t('券名称'),
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: this.$t('面额'),
          align: 'right',
          dataIndex: 'value',
          customRender: (text, r) => {
            return r.value.toFixed(0);
          }
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state',
          scopedSlots: { customRender: 'state' },
        },
        {
          title: this.$t('有效期'),
          align: 'center',
          dataIndex: 'time',
        },
        {
          title: this.$t('来源'),
          align: 'center',
          dataIndex: 'getType_dictText',
        },
        {
          title: this.$t('获取时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('使用时间'),
          align: 'center',
          dataIndex: 'updateTime',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      couponDataSource: [],
      //限时币
      limitCoin: {
        state: '0',
        source: undefined,
      },
      limitCoinColumns: [
        {
          title: this.$t('编号'),
          align: 'center',
          dataIndex: 'id',
        },
        {
          title: this.$t('名称'),
          align: 'center',
          dataIndex: 'goodsName',
        },
        {
          title: this.$t('总币值'),
          align: 'right',
          dataIndex: 'totalCoin',
          customRender: (text, r) => {
            return r.totalCoin.toFixed(2);
          }
        },
        {
          title: this.$t('剩余币值'),
          align: 'right',
          dataIndex: 'remainCoin',
          customRender: (text, r) => {
            return r.remainCoin.toFixed(2);
          }
        },
        {
          title: this.$t('状态'),
          align: 'center',
          dataIndex: 'state',
          scopedSlots: { customRender: 'state' },
        },
        {
          title: this.$t('有效期'),
          align: 'center',
          dataIndex: 'time',
        },
        {
          title: this.$t('来源'),
          align: 'center',
          dataIndex: 'source_dictText',
        },
        {
          title: this.$t('获取时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('最后消费时间'),
          align: 'center',
          dataIndex: 'updateTime',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      limitCoinDataSource: [],
      //卡
      loadings: false,
      cardModel: {
        state: 0,
        chipNo: '',
      },
      cardColumns: [
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
        },
        {
          title: this.$t('卡状态'),
          align: 'center',
          dataIndex: 'state_dictText',
        },
        {
          title: this.$t('取卡费'),
          align: 'right',
          dataIndex: 'cardFee',
          customRender: (text, r) => {
            return r.cardFee.toFixed(2);
          }
        },
        {
          title: this.$t('取卡时间'),
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
        {
          title: this.$t('操作'),
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        },
      ],
      cardDataSource: [],
      //消费记录
      recordsModel: {
        typeId: undefined,
        createBy: '',
        deviceId: '',
      },
      recordsColumns: [
        {
          title: this.$t('时间'),
          align: 'center',
          dataIndex: 'createTime',
          scopedSlots: { customRender: 'createTime' },
        },
        {
          title: this.$t('业务类型'),
          align: 'center',
          dataIndex: 'typeId_dictText',
        },
        {
          title: this.$t('交易币值'),
          align: 'right',
          dataIndex: 'coinValue',
        },
        {
          title: this.$t('交易后币值'),
          align: 'right',
          dataIndex: 'coinAfter',
        },
        {
          title: this.$t('交易积分'),
          align: 'right',
          dataIndex: 'integralValue',
          customRender: (text, r) => {
            return r.integralValue.toFixed(0);
          }
        },
        {
          title: this.$t('交易后积分'),
          align: 'right',
          dataIndex: 'integralAfter',
          customRender: (text, r) => {
            return r.integralAfter.toFixed(0);
          }
        },
        {
          title: this.$t('交易彩票'),
          align: 'right',
          dataIndex: 'lotteryValue',
          customRender: (text, r) => {
            return r.lotteryValue.toFixed(0);
          }
        },
        {
          title: this.$t('交易后彩票'),
          align: 'right',
          dataIndex: 'lotteryAfter',
          customRender: (text, r) => {
            return r.lotteryAfter.toFixed(0);
          }
        },
        {
          title: this.$t('交易A票'),
          align: 'right',
          dataIndex: 'alotteryValue',
          customRender: (text, r) => {
            return r.alotteryValue.toFixed(0);
          }
        },
        {
          title: this.$t('交易后A票'),
          align: 'right',
          dataIndex: 'alotteryAfter',
          customRender: (text, r) => {
            return r.alotteryAfter.toFixed(0);
          }
        },
        {
          title: this.$t('交易A币'),
          align: 'right',
          dataIndex: 'pointsValue',
          customRender: (text, r) => {
            return r.pointsValue.toFixed(0);
          }
        },
        {
          title: this.$t('交易后A币'),
          align: 'right',
          dataIndex: 'pointsAfter',
          customRender: (text, r) => {
            return r.pointsAfter.toFixed(0);
          }
        },
        {
          title: this.$t('交易限时币'),
          align: 'right',
          dataIndex: 'limitCoinValue',
          customRender: (text, r) => {
            return r.limitCoinValue.toFixed(0);
          }
        },
        {
          title: this.$t('交易后限时币'),
          align: 'right',
          dataIndex: 'limitCoinAfter',
          customRender: (text, r) => {
            return r.limitCoinAfter.toFixed(0);
          }
        },
        {
          title: this.$t('机号'),
          align: 'center',
          dataIndex: 'machineNo',
        },
        {
          title: this.$t('机台名称'),
          align: 'center',
          dataIndex: 'gameId_dictText',
        },
        {
          title: this.$t('交易设备'),
          align: 'center',
          dataIndex: 'devide',
        },
        {
          title: this.$t('操作员'),
          align: 'center',
          dataIndex: 'createBy',
        },
      ],
      recordsDataSource: [],
      loading: false,
      ipagination: {
        current: 1,
        pageSize: 30,
        pageSizeOptions: ['10', '20', '30'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + this.$t('sum-total', { total: total })
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0,
        onShowSizeChange: (current, pageSize) => this.handleSizeChange(current, pageSize),
      },
      userList: [],
      deviceList: [],
    }
  },
  created() {
    getAction('/bis/bisSysParameter/list', { name: 'appletAuthRecharge' }).then((res) => {
      if (res.success) {
        if (res.result.records.length > 0 && res.result.records[0].ivalue) {
          this.appletAuthRecharge = true
        } else {
          this.appletAuthRecharge = false
        }
      }
    })
  },
  methods: {
    add() {
      this.visible = true
    },
    edit(record) {
      this.visible = true
      this.model = Object.assign({}, record)
      console.log(this.model)
      let validityEnd = record.memberAccount.validityEnd ? record.memberAccount.validityEnd : this.$t('不限期')
      this.memberAccount = Object.assign({}, record.memberAccount, { validityEnd: validityEnd })
      if (this.model.wxHeadImg) {
        this.picUrl = true
      }
      this.memberAccount.coin = parseFloat(this.memberAccount.presentCoin) + parseFloat(this.memberAccount.realCoin)
      this.activeKey = '1'
      this.callback('1')
    },
    callback(key, arg) {
      if (key == '1') {
        this.getProfile()
      }
      if (key == '2') {
        this.getPiao(1)
      }
      if (key == '3') {
        this.couponSearchQuery(1)
      }
      if (key == '6') {
        this.limitCoinSearchQuery(1)
      }
      if (key == '4') {
        this.cardSearchQuery()
      }
      if (key == '5') {
        this.getRecordsList(1)
        getAction('/sys/user/list').then((res) => {
          if (res.success) {
            this.userList = res.result.records
            this.userList.forEach((col) => {
              col.id = col.realname
            })
            this.userList.unshift({ id: '', realname: this.$t('全部') })
          }
        })
        getAction('/device/bisDeviceInfo/list').then((res) => {
          if (res.success) {
            this.deviceList = res.result.records
            this.deviceList.unshift({ id: '', name: this.$t('全部') })
          }
        })
      }
    },
    // 会员采集数据
    getProfile() {
      getAction('/member/bisMemberProfile/list', {memberId : this.model.id})
        .then((res) => {
          if (res.success) {
            if(res.result.records.length > 0){
              this.profile = res.result.records[0]
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
        })
    },
    //门票
    getPiao(num) {
      let query = {}
      query.memberId = this.model.id
      this.ipagination.current = num
      query.pageNo = this.ipagination.current
      query.pageSize = this.ipagination.pageSize
      query.state = this.piaoModel.state
      query.goodsName = this.piaoModel.goodsName
      query.column = 'createTime'
      query.order = 'desc'
      getAction('/member/bisMemberTicket/list', query).then((res) => {
        if (res.success) {
          this.piaoDataSource = res.result.records
          this.piaoDataSource.forEach((col) => {
            if (col.validityStart == null || col.validityStart == undefined) {
              col.validity = this.$t('不限期')
            } else {
              col.validity = col.validityStart + '~' + col.validityEnd
            }
            if (col.state != '3') {
              col.updateTime = ''
            }
            if (col.form_dictText == this.$t('年票')) {
              col.remainNumber = this.$t('不限次')
              col.totalNumber = this.$t('不限次')
            }
          })
          if (res.result.total) {
            this.ipagination.total = res.result.total
          } else {
            this.ipagination.total = 0
          }
        }
      })
    },
    //作废门票
    handleInvalid(record) {
      this.confirmLoading = true
      let query = {}
      query.id = record.id
      query.state = '4'
      putAction('/member/bisMemberTicket/editState', query)
        .then((res) => {
          if (res.success) {
            this.$message.success(res.message)
            this.getPiao(1)
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.confirmLoading = false
        })
    },
    //优惠券
    couponSearchQuery(num) {
      this.couponDataSource = []
      let query = {}
      query = this.coupon
      query.memberId = this.model.id
      this.ipagination.current = num
      query.pageNo = this.ipagination.current
      query.pageSize = this.ipagination.pageSize
      query.column = 'createTime'
      query.order = 'desc'
      this.loadings = true
      getAction('/member/bisMemberCoupon/list', query)
        .then((res) => {
          if (res.success) {
            if (res.result.records.length > 0) {
              res.result.records.forEach((col) => {
                if (col.startDate == undefined) {
                  col.time = this.$t('不限期')
                } else {
                  col.time = col.startDate + '~' + col.endDate
                }
                this.couponDataSource.push(col)
              })
            } else {
              this.couponDataSource = res.result.records
            }
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          }
        })
        .finally(() => {
          this.loadings = false
        })
    },
    couponDel(record) {
      let query = {}
      query.id = record.id
      query.state = '4'
      postAction('/member/bisMemberCoupon/edit', query).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.couponSearchQuery(1)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    //限时币
    limitCoinSearchQuery(num) {
      this.limitCoinDataSource = []
      let query = {}
      query = this.limitCoin
      query.memberId = this.model.id
      this.ipagination.current = num
      query.pageNo = this.ipagination.current
      query.pageSize = this.ipagination.pageSize
      this.loadings = true
      getAction('/member/bisMemberLimitCoin/list', query)
        .then((res) => {
          if (res.success) {
            if (res.result.records.length > 0) {
              res.result.records.forEach((col) => {
                if (col.validityEnd == undefined) {
                  col.time = this.$t('不限期')
                } else {
                  col.time = col.validityStart + '~' + col.validityEnd
                }
                this.limitCoinDataSource.push(col)
              })
            } else {
              this.limitCoinDataSource = res.result.records
            }
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          }
        })
        .finally(() => {
          this.loadings = false
        })
    },
    limitCoinDel(record) {
      let query = {}
      query.id = record.id
      query.state = '4'
      postAction('/member/bisMemberLimitCoin/edit', query).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.limitCoinSearchQuery(1)
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    //会员卡
    cardSearchQuery() {
      this.loadings = true
      let query = {
        memberId: this.model.id,
        chipNo: this.cardModel.chipNo,
        state: this.cardModel.state,
        pageNo: 1,
        pageSize: 99,
      }
      getAction('/member/bisMemberCard/list', query)
        .then((res) => {
          if (res.success) {
            this.cardDataSource = res.result.records
          }
        })
        .finally(() => {
          this.loadings = false
        })
    },
    getRecordsList(num) {
      let that = this
      that.loading = true
      let querydata = {}
      querydata.memberId = that.model.id
      that.ipagination.current = num
      querydata.pageNo = that.ipagination.current
      querydata.pageSize = that.ipagination.pageSize
      querydata.createTime_begin = that.recordsModel.createTime_begin
      querydata.createTime_end = that.recordsModel.createTime_end
      querydata.typeId = that.recordsModel.typeId
      querydata.createBy = that.recordsModel.createBy
      querydata.deviceId = that.recordsModel.deviceId
      querydata.column = 'createTime'
      querydata.order = 'desc'
      getAction('/member/bisMemberAccountChange/list', querydata)
        .then((res) => {
          if (res.success) {
            that.recordsDataSource = res.result.records
            that.recordsDataSource.forEach((col) => {
              col.coinValue = col.realCoinValue + col.presentCoinValue
              col.coinValue = col.coinValue.toString().indexOf('.') > -1 ? col.coinValue.toFixed(2) : col.coinValue.toFixed(2)
              col.coinAfter = col.realCoinAfter + col.presentCoinAfter
              col.coinAfter = col.coinAfter.toString().indexOf('.') > -1 ? col.coinAfter.toFixed(2) : col.coinAfter.toFixed(2)
              if (col.deviceId_dictText != null) {
                col.devide = col.deviceId_dictText + '(' + col.deviceId + ')'
              } else {
                col.devide = ' '
              }
            })
            if (res.result.total) {
              that.ipagination.total = res.result.total
            } else {
              that.ipagination.total = 0
            }
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
    handleOk() {
      let query = {}
      if(this.model.memberCards.length == 0 && !this.model.phone && !this.model.email){
        this.$message.warn(this.$t('手机号和邮箱不能同时为空'))
        this.$refs.phone.focus()
        return
      }
      query = Object.assign({}, this.model)
      putAction('/member/bisMemberInfo/edit', query).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$emit('ok')
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    //解绑
    unbundle() {
      let query = {}
      query.order = {
        typeId: 24,
      }
      query.memberInfo = {
        id: this.model.id,
        chipNo: this.model.memberCards[0].chipNo,
      }
      postAction('/trans/trans', query).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.close()
          this.$emit('ok')
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handlePiaoTableChange(pagination, filters, sorter) {
      this.getPiao(pagination.current)
    },
    handleCouponTableChange(pagination, filters, sorter) {
      this.couponSearchQuery(pagination.current)
    },
    handleLimitCoinTableChange(pagination, filters, sorter) {
      this.limitCoinSearchQuery(pagination.current)
    },
    handleTableChange(pagination, filters, sorter) {
      this.getRecordsList(pagination.current)
    },
    close() {
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    viewTicketDetail(record) {
      this.$refs.ticketDetails.edit(record)
    },
    showOrder(record) {
      let order = {}
      getAction('/order/bisOrder/list', { id: record.orderId }).then((res) => {
        if (res.success) {
          order = res.result.records[0]
          this.$refs.typeNameForm.edit(order)
        }
      })
    },
    handleSizeChange(current, pageSize) {
      this.ipagination.pageSize = pageSize
    },
    editmemberLimit(record){
      this.$refs.limit.show(record)
    }
  },
}
</script>
<style scoped>
.customHeight.customHeightChild .customForm >>> .ant-form-item-label {
  background: none;
  border: none;
}
.customHeight
  .smallTable
  >>> .ant-table-small
  > .ant-table-content
  > .ant-table-body
  > table
  > .ant-table-thead
  > tr
  > th {
  background-color: rgb(205, 210, 233);
  font-size: 14px;
  font-weight: 600;
  border-right: 1px solid white;
  color: 'rgb(49,49,49)';
}
.customHeight.customHeightChild .customForm >>> .ant-form-item-control-wrapper {
  border: none;
}
.customHeight.customHeightChild >>> .ant-form-item .ant-form-item-control {
  height: auto;
}
.noImageError .has-error .ant-form-explain {
  position: absolute;
  bottom: 2px;
}
.noImageError .ant-upload.ant-upload-select-picture-card,
.noImageError .ant-upload-list-picture-card-container {
  width: 90px;
  height: 90px;
  margin-bottom: 11px;
}
</style>